package com.joysuch.wwyt.openapi.controllers.controllerV1;

import com.joysuch.wwyt.core.exception.ApiCoreException;
import com.joysuch.wwyt.dzhapi.dto.BuildDataDto;
import com.joysuch.wwyt.dzhapi.service.ApiTokenVerifyService;
import com.joysuch.wwyt.openapi.controllers.controllerV1.req.ApiV1QueryListReq;
import com.joysuch.wwyt.openapi.controllers.controllerV1.vo.ApiPagePropertyDataVo;
import com.joysuch.wwyt.openapi.exception.ApiV1ExceptionCodeMsg;
import com.joysuch.wwyt.openapi.result.ApiV1Result;
import com.joysuch.wwyt.openapi.services.serviceV1.ApiV1BpWorkService;
import com.joysuch.wwyt.openapi.services.serviceV1.ApiV1TokenVerifyService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * @author: JamesZY
 * @date: 2021/8/24
 * @description:工种接口
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/work")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ApiV1BpWorkController {
    private final ApiV1BpWorkService service;
    private final ApiTokenVerifyService verifyService;

    /**
     * 分页查询
     */
    @PostMapping("/list")
    public ApiV1Result search(@RequestBody @Valid ApiV1QueryListReq req, HttpServletRequest request) {
        ApiPagePropertyDataVo apiPagePropertyDataVo = null;
        BuildDataDto buildDataDto;
        try {
            buildDataDto = verifyService.verifyToken(request);
            apiPagePropertyDataVo = service.searchAll(req,buildDataDto);
        } catch (ApiV1ExceptionCodeMsg e) {
            return ApiV1Result.error(e.getCode(), e.getMessage());
        }
        return ApiV1Result.success(apiPagePropertyDataVo);
    }
}
